using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace System.Drawing.Drawing2D
{
    /// <summary>
    /// 
    /// </summary>
    [TypeConverter(typeof(ExpandableObjectConverter))]
    public class Line : ICloneable
    {
        private Color lineColor = Color.FromKnownColor(KnownColor.WindowFrame);
        private LineJoin lineJoin = LineJoin.Miter;
        private DashStyle lineStyle = DashStyle.Solid;
        private int lineWidth = 1;

        public Line()
        {
        }

        public event EventHandler ColorChanged;

        public event EventHandler JoinChanged;

        public event EventHandler StyleChanged;

        public event EventHandler WidthChanged;

        [DefaultValue(typeof(Color), "WindowFrame")]
        public Color Color
        {
            get { return lineColor; }
            set
            {
                if (lineColor != value)
                {
                    lineColor = value;
                    if (ColorChanged != null)
                        ColorChanged(this, new EventArgs());
                }
            }
        }

        [DefaultValue(LineJoin.Miter)]
        public System.Drawing.Drawing2D.LineJoin Join
        {
            get { return lineJoin; }
            set
            {
                if (lineJoin != value)
                {
                    lineJoin = value;
                    if (JoinChanged != null)
                        JoinChanged(this, new EventArgs());
                }
            }
        }

        [DefaultValue(DashStyle.Solid)]
        public System.Drawing.Drawing2D.DashStyle Style
        {
            get { return lineStyle; }
            set
            {
                if (lineStyle != value)
                {
                    if (value == DashStyle.Custom)
                        throw new ArgumentException("Custom line style not supported", "LineStyle");
                    lineStyle = value;
                    if (StyleChanged != null)
                        StyleChanged(this, new EventArgs());
                }
            }
        }

        [DefaultValue(1)]
        public int Width
        {
            get { return lineWidth; }
            set
            {
                if (lineWidth != value)
                {
                    lineWidth = value;
                    if (WidthChanged != null)
                        WidthChanged(this, new EventArgs());
                }
            }
        }

        public object Clone()
        {
            return this.MemberwiseClone();
        }

        public Pen GetPen()
        {
            Pen p = new Pen(lineColor, lineWidth);
            p.DashStyle = lineStyle;
            p.Alignment = PenAlignment.Inset;
            p.LineJoin = lineJoin;
            return p;
        }
    }
}